package com.xwltz.core.utils;

import cn.hutool.core.util.ObjectUtil;
import com.xwltz.core.exception.ServiceException;

import java.lang.reflect.InvocationTargetException;

/**
 * @description ObjectUtils
 * @information on version 1.0 be created by @xwltz at 2022/5/11 18:06
 */
public class ObjectUtils extends ObjectUtil {

	public static <E> E getInstance(Class<E> clazz) {
		try {
			return clazz.getDeclaredConstructor().newInstance();
		} catch (InstantiationException | NoSuchMethodException e) {
			e.printStackTrace();
			throw new ServiceException(String.format("初始化 [%s] 对象失败, 请确保对象的默认构造函数可用", clazz.getName()), e);
		} catch (InvocationTargetException | IllegalAccessException e) {
			throw new ServiceException(String.format("初始化 [%s] 对象失败, 请确保对象的默认构造函数可用", clazz.getName()), e);
		}
	}
}
